﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TamTreSoSinh.DBContext;

namespace TamTreSoSinh.Admin
{
    public partial class SettingContactInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            LoadData();
        }

        private void LoadData()
        {
            DBTamTreEntities dbContext = new DBTamTreEntities();
            ContactInfo contactInfo = dbContext.ContactInfoes.FirstOrDefault();
            if (contactInfo == null)
            {
                // CreateNew
                contactInfo = new ContactInfo() { ContactContent = string.Empty };
                dbContext.ContactInfoes.AddObject(contactInfo);
                dbContext.SaveChanges();
            }

            txtContent.Text = contactInfo.ContactContent;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            DBTamTreEntities dbContext = new DBTamTreEntities();
            ContactInfo contactInfo = dbContext.ContactInfoes.FirstOrDefault();
            if (contactInfo == null)
            {
                return;
            }

            contactInfo.ContactContent = txtContent.Text;

            dbContext.SaveChanges();
        }
    }
}